<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui">

<ui:composition template="/_setor.xhtml">
	<ui:define name="corpo">

		<div id="conteudo">
			<h:form id="form">

				<h2>
					<h:outputText value="Cadastro de Setor" />
				</h2>
				
				<p:growl id="grow" showDetail="true" sticky="true">
				<p:messages id="msg" />
				
				<p:fieldset legend="Dados do Setor" style="background-image: url(resources/imagens/72.jpg);">
					<br />					
						<!-- Em vez de colocar nome do orgão incluir a sigla do orgão -->

						<h:outputLink value="javascript:void(0)" onclick="dlgSetor.show();">
						<h:outputLabel value="Orgao: " />
					</h:outputLink>
					<p:inputText id="orgao" required="true" requiredMessage="Preencha o campo Orgão"
						value="#{setorBean.setor.orgao.sigla}"
						onclick="dlgSetor.show();" readonly="true" onchange="handler">
					</p:inputText>
						<br />	

						<h:outputLabel value="Setor: " for="setor" />
						<p:inputText id="setor" value="#{setorBean.setor.nome}" required="true"
							requiredMessage="Preencha o Campo Setor">
							<f:ajax event="change" />
						</p:inputText>

						<br />
					<p:commandButton value="Cadastrar" action="#{setorBean.grava}"
						image="ui-icon-disk" update="msg">
						<f:ajax render="@all" />
					</p:commandButton>

				</p:fieldset>
				</p:growl>

			</h:form>

			<p:dialog header="Orgão" widgetVar="dlgSetor" modal="true"
				width="500" showEffect="hide" hideEffect="fade" resizable="false" >
				<h:form id="form1">

					<p:outputPanel id="orgaos">
						<p:dataTable value="#{orgaoBean.orgaos}" var="orgao"
							paginator="true" rows="5" selectionMode="single" >

							<p:column filterBy="#{orgao.sigla}" filterMatchMode="contains"
								headerText="Sigla">
								<h:commandLink value="#{orgao.sigla}" onclick="dlgSetor.hide()"
									id="orgao">
									<f:setPropertyActionListener target="#{setorBean.setor.orgao}" value="#{orgao}" />
								</h:commandLink>
							</p:column>	
								
							<p:column headerText="Nome" sortBy="#{orgao.nome}">
								<h:outputText value="#{orgao.nome}" />
							</p:column>

						</p:dataTable>
					</p:outputPanel>
				</h:form>
			</p:dialog>



		</div>

	</ui:define>
</ui:composition>

</html>
